Perceptually lossless color compression

ABSTRACT

A system and method of color data compression may perform variations of MRC compression including taking into consideration means and/or variances within k×k cells of an image, background texture, background smoothed color, and gradient components for determination of which parts of an image belong to the background and foreground MRC layers, for calculating thresholds values for such determinations, and determining correctness of determined thresholds and polarity, and may determine the background and foreground layer colors based on the variances, the gradient components, and neighboring pixels of non-color-assigned pixels of the background and foreground layers.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.12/206,707, filed Sep. 8, 2008, which claims priority to U.S.Provisional Pat. App. Ser. No. 60/967,815, filed Sep. 7, 2007, theentire content of each of which is herein incorporated by reference.

FIELD OF THE INVENTION

The present invention relates to a system and method for performingperceptually lossless color compression, and, in particular, to suchcompression using variations of Mixed Raster Content (MRC) compression.

BACKGROUND INFORMATION

Perceptually Lossless Color Compression is desirable in the field ofdigital imaging, in particular, with application to improved performanceof network and mobile imaging devices. Conventional systems provideeither lossy or lossless compression, neither of these modes beingadequate for most digital imaging or remote capture applications.Lossless compression in colorspace generates very large file sizes,unsuitable for distributed databases and other applications wheretransmission or hosting size is a factor. Lossy compression assumes animplicit tradeoff between bitrate and distortion so that the higher thecompression, the greater the level of distortion. One exampleconventional compression method is MRC compression. (See Mixed RasterContent (MRC) Model for Compound Image Compression, Ricardo de Queirozet al., Corporate Research & Technology, Xerox Corp., available athttp://image.unb.br/queiroz/papers/ei99mrc.pdf, and see U.S. Pat. No.7,110,137, the entire disclosures of which are incorporated herein byreference.) In MRC coding, there is typically a foreground layer, abackground layer, and a mask (or selector layer) which has a binaryvalue that determines whether a pixel in the image is given the colorvalue of the foreground or background layer. With respect to businessdocuments, the mask layer is an important layer, which generallycontains the text and line art information. Since the mask layer is soimportant, it is generally encoded with the same resolution as theoriginal image, even though this may have a high byte cost. In fact, forvery low resolution images, the mask layer may even be of a higherresolution than the original image. The foreground layer assigns a colorto those pixels that the mask places in the foreground, while thebackground layer assigns a color value to the remaining pixels. Both theforeground and background layers are generally encoded at a lowerresolution than the original image.

However, what is desired, in fact, neither of these methods achieves: avery high compression rate with no perceptual distortion. Manyapplications and devices, including digital copiers and MFPs, need ahigh degree of compression on color scanned documents. For documents tobe used effectively as e-mail attachments or in a web-hostedenvironment, lossless compression is not viable. Even for sensitivemedical applications, including CAT and MRI scans, lossless compressionis not used in the industry. However, for many applications, includingcorporate document record archiving, no perceptual loss can be toleratedas these image documents are often treated as the documents of record.

SUMMARY

Embodiments of the present invention provide systems and methods thatachieve very high rates of compression on color scanned documents withminimized loss, e.g., no perceptual loss. These systems and methodsgenerally do not accept the standard compression rule that there isalways an implicit rate/distortion tradeoff Rather, the perceptuallylossless compression of the present invention may be computervision-based such that compression is achieved by inverting the seriesof graphics and/or printing steps that were used initially in imagegeneration. As such, the systems and methods of the present inventionmay understand as fully as possible whether a given image satisfies acertain set of constraints before trying to “deconstruct” and compressthe image.

In an example embodiment of the present invention, a system and methodmay be provided that is segmentation-based and falls under the categoryof the general MRC coding compression method. This method may rely onaccurate segmentation of an image into its constituent parts, optionallyenhancing certain components, and then using layer-based separation andregion-specific coding methods. Dividing the document into distinctlayers offers advantages for both image quality and compression, as eachlayer can be given a different level of quality setting and resolutionreduction. It also assists in efficient OCR of the image, as the masklayer may be presented directly to an OCR engine. For the most accurateresults, both the mask layer and either the original or a processedcolor image may be shown to an OCR engine, with the results combined ina such a manner that when they differ, the values presumed to be moreaccurate are chosen.

In an example embodiment of the present invention, computer-vision basedmethods of image understanding may be provided. Pixels may be convertedinto objects, and these objects may then be used to form a hierarchicalimage decomposition, where this decomposition is then used in thecompression process. This conversion of the image into salient objects,in a hierarchical structure, including connected components, words,lines, text and picture regions, etc., is akin to human visual imageprocessing. A properly segmented image, in line with human segmentation,can achieve much better compression rates, with no perceptual loss, ascompared to non-Boolean JPEG (DCT) and wavelet based methods.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 shows selection of a dark and a light pixel value along aparallel direction to a gradient direction for insertion of the valuesinto arrays in a threshold value determination method, according to anexample embodiment of the present invention.

DETAILED DESCRIPTION Preprocessing

Method to Find Halftone Screens and Texture Before Smoothing

A constant color of an original input object may be provided using ascreening pattern, where the actual included color is a combination of afew colors in a pattern that at a distance looks like the originalcolor. Since the color is provided using a color combination, the singlecolor is susceptible to incorrect interpretation by a processor as astructure to be represented in a mask layer of MRC coding for inclusionas a foreground object. In an example embodiment of the presentinvention, the system and method may determine that the screen is not tobe interpreted as a structure. In this case, the system and method maysmooth the pixels of the background. The screening structure mayaccordingly be softened.

Initially, the system and method may find halftone and texture portionsand determine that these belong to the background. The system and methodmay accordingly selectively smooth only these portions and not, forexample, text. On the other hand, when conventional systems smooth animage, the entire image as a whole, regardless of whether it includestext or not.

To find the regions that need smoothing, the system may look at thevariance in a section of k×k cells. Grayscale variance may first beobtained for each such section. Then the section may be smoothed.Subsequently, the variance may be re-calculated. The system and methodmay then compare the two variances to obtain a ratio. If the ratio ismore than, e.g., 5; or, if the ratio is less than 5 and at least, e.g.,2, and the recomputed variance is less than some threshold number, ineither case, the system and method may perform the smoothing in a morepermanent manner.

Accordingly, the system and method may divide the color image into cellsof k×k pixels, where a typical value for k is 16, compute the varianceof each k×k cell, smooth the k×k cell using an integer-based uniformsmoothing function, and re-compute the variance. It may be assumed thatthe k×k cell is a screened halftone color region when any one of thefollowing conditions is satisfied:

i. if the ratio of original variance to the recomputed variance aftersmoothing exceeds some ratio r1, e.g., 5; and

ii. the ratio exceeds some lesser ratio r2, e.g., 2, and the recomputedvariance is less than some value v, e.g., 30.

Alternatively, instead of using variance, the system and method maycompute the gradient image and eliminate all non-maximal gradient pointsfor this image G, such that the edge map—where pixels are “on” onlywhere there is an edge—is computed for this image. The system and methodmay then analyze each k×k block, where k is, e.g., 16 or 32, in G todetermine the number of gradient points Ng—points at which a changeoccurs, represented by a black pixel in the gradient image, the numberof gradient endpoints Ne—a gradient point having only one other gradientpoint in its surrounding eight neighbors, and the number of singletongradient point Ns—a gradient point having no turned on neighbor in its 8basic directions (north, south, east, and west). Based on thesedeterminations, the system and method may determine whether theconsidered region should be classified as a screened halftone. Forexample, where k=32, values for determining that smoothing should beperformed may be Ng>400 and Ne>35 and Ns>20, in which case the cell maybe classified as screened halftone.

Method to Smooth Halftone Screens and Texture Without Distortion of TextRegions

The regions determined by the system and method to be candidates forsmoothing might still include some text.

Accordingly, for every k×k cell where a halftone screen was detected asdescribed above, the system and method may perform the smoothing in thefollowing manner. An initial smoothing, which may be an integer-basedapproximation of a Gaussian, may be applied to the cells. One typicalsmoothing implementation is where all eight neighbors are equallyweighted, with their combined weight equal to the weight of the centerpixel.

Next, the system and method may determine the background, descreenedcolor—the single color that represents the screening pattern of thevarious colors. The descreened color may be determined as follows: foreach non-overlapping 2×2 sub-cell of the original image, determine thevariance, sort the sub-cells by increasing variance, select all 2×2sub-cells whose variance is in the lowest quartile, and compute themedian color value of the selected sub-cells. The median color value maybe used as the approximate background color value.

To preserve the text in the k×k block, if any, the system and method maythen re-visit each 2×2 sub-cell and apply a uniform smoothing only ifthe color mean of the sub-cell is within some distance Dc, e.g., 20, ofthe median color of the k×k cell.

Method to Smooth Halftone Screen and Textured Regions, But Not Text, asa Function of Texture/Halftone Strength

Where the smoothing is to be applied, the degree of smoothing, both forscreened halftone texture regions and for general texture regions, canbe calibrated to fit the strength of the texture. The strength of thetexture may determine the weights of the Gaussian function of radius one(neighborhood of one pixel away) that is to be used for smoothing. Forvery strong texture of a 2×2 to which the pixel belongs (e.g., wherethere is a high variance), the smoothing function may approximate auniform blur—a pure average (a strong smoothing); for very weak texture,the center pixel may be more heavily weighted.

Strength of texture can be determined by degree of variance.

Segmentation Solving for Background Surfaces

Page Analysis of Constant Regions

Frequently a page will have a relatively flat background, which can makeit easier for the system and method to segment the page into itsrespective foreground, background and mask layers. Every pixel on thepage is converted to a grayscale value and placed into a histogram from0 to 255. The maximum peak of the histogram is then identified. If morethan a certain percentage (commonly 40%, 50% or 60%) of the grayscalevalues are within a range (usually 10 or 15) of the peak, the system andmethod looks for constant regions, as described below.

Method to Detect Constant Regions

In an example embodiment of the present invention, the system and methodmay find where there are constant regions in the input image. This mayallow for reducing the size of image and for the printing to beperformed by the printer in a very quick manner.

A quadtree may be used for region labeling. In other words, the systemand method may first analyze the highest node, e.g., including 32×32pixels. If the values are constant in the node, then the system andmethod may move on. If not constant, then the system and method mayexamine the level below for constant color, and so on.

Where there is a large region of approximately constant color, then thesystem and method may classify those regions as having constant color.But some of the lower 2×2s may also be determined as belonging to thelarge region that has the constant color.

Accordingly, to determine the flat regions in the image—the regionshaving constant color, a quadtree approach may be used, with the toplevel of the quadtree consisting of the smallest square necessary tocontain the entire image. With all quadtrees, the dimensions of thesquares are of form k×k, where k is equal to 2̂n for some integer n.Starting from this top level of the quadtree, the system and method mayrecursively subdivide the quadtree (into children) until squares of size2×2 are reached. Each of these 2×2 blocks is given a unique index. Foreach 2×2, the system and method may label it a “constant region block”if the variance of the block is below a threshold T, e.g., 70. Thesystem and method may compute the mean of each of the constant region2×2 blocks and add these newly determined constant regions to theconstant region list of 2×2 blocks. (At this point, the list for each2×2 will consist only of itself.) The system and method may then go upeach level of the quadtree. At each level, the parent looks at the listsof its four children, and attempts to combine them into as few lists aspossible. To do this, the system and method may iterate through thearray of regions and compare them two at a time. If two regions have amean that is within a certain tolerance Tcm, and if the variance of theunion of the two regions is below a threshold Tcv, the system and methodmay combine the two lists.

When the top level of the quadtree is reached, the system and method maysort all available constant region lists by their size. All the constantregions with a size less than threshold Tcr may be eliminated. Allremaining constant regions can be used for segmentation purposes.

Alternatively, constant region detection can be accomplished usingoverlapped pyramids.

Method to Threshold Components Using Assuming Flat Background

Once the constant color region is found, the system and method mayallocate to the background layer all pixels that are within a toleranceof the constant color. Remaining pixels may be allocated to theforeground layer. The system and method may calculate the foregroundcolor as the average of the remaining pixels allocated to the foregroundlayer. However, this method may result in false positives with respectto the foreground layer.

Having computed a flat background region, i.e., a constant colorbackground region, and determined the remaining connected components ofthe intensity or color image (intensity image is a grayscale of theoriginal image), the system and method may then extract the smallertextual components as discussed below in the section entitled “Solvingfor foreground text.”

But this may still be imprecise since there can be some backgroundpixels attached to the foreground.

Accordingly, the system and method may compute the average intensityvalue for all the text components, e.g., the smaller textual componentsdiscussed below in the section entitled “Solving for foreground text.”This intensity may be approximated as the foreground text intensity.Subsequently, the system and method may revisit each of the textcomponents discussed below in the section entitled “Solving forforeground text.” For each such component, the system and method mayvisit all the pixels in the component's bitmap comparing the pixels'intensities with the background intensity and the approximate foregroundintensity. For each pixel, if the intensity is closer to the backgroundintensity the system and method may re-label the pixel as backgroundand, otherwise, maintain its label as foreground.

In one implementation, this can be applied iteratively untilconvergence, i.e., until re-labeling is no longer performed. That is,the system and method may, in each iteration, compute another average ofthe text and, for each pixel, re-determine whether the pixel's value iscloser to the background or to the text color. This may be done untilthe values of all remaining pixels are closer to the text.

Method to Detect Constant Halftone and Texture Blocks

In an example embodiment of the present invention, the methods describedin this section and in the section entitled “Method to detect constanthalftone and texture regions” may be used instead of that described inthe section above entitled “Method to detect constant regions” where theconstant regions include a high variance.

In an example embodiment of the present invention, the system and methodmay determine whether a block is a texture block.

The system and method may divide the image into k×k regions, where k is,e.g., 32. Those regions by the boundary may have their regions filledwith padded pixels. The k×k regions may be subdivided into j×jsub-blocks, where j is, e.g., 4. For each j×j sub-block, the system andmethod may compute its mean and variance. For each k×k block, the systemand method may compute the difference, Dm, between the maximum mean andthe minimum mean of its j×j sub-blocks. The system and method may alsocompute the ratio, Rv, of the maximum variance to the minimum varianceof its j×j sub-blocks. For each k×k block, if Dm is less than thethreshold value Tm and Rv is less than the threshold value Tv, thesystem and method may consider this block to be a texture block.

While this method can be used independently of the method mentioned inthe section above entitled “Method to detect constant regions,” in oneexample embodiment it is only used for those regions which were notpreviously determined to be constant color.

Method to Detect Constant Halftone and Texture Regions

Similar texture blocks may be merged into regions. In order to gettexture regions, and not just texture blocks, the system and method canconsider each of the 32×32 regions mentioned in the section aboveentitled “Method to detect constant halftone and texture blocks” to bethe lowest level of a quadtree, which may then be processed in a mannersimilar to the section above entitled “Method to detect constantregions,” with different values of T, Tcm and Tcv. (The mean andvariance of two blocks must each be within respective distances todetermine that they are to be joined).

Method to Detect Smoothly Varying (Non-Textured) Background Regions

The background colors can change very slightly from one color to anotherin the background image. Failure to recognize such change may causeerrors. When the background color changes slowly across a document, itis important to recognize and preserve this quality. Failure to do somay result in visible distortions, such as mistakenly dividing thebackground into several distinct constant color regions.

Accordingly, in an example embodiment of the present invention, afterthe flat region detection (see the section above entitled “Method todetect constant regions”), the system and method may analyze all theregions that are spatially connected (e.g., each two of the various k×ksections that have been connected to form regions of constant color maybe analyzed) to determine if their mean background colors are slowlyvarying, i.e., their means are very close to each other. If their meanbackground colors are slowly varying, the system and method may mergethem into a smoothly varying background region. Using a background colorcompression filter, such as DCT (discrete cosine transform), may ensurethat this property of edge-free slow background change will be preservedin the encoded image.

Method to Detect Constant Regions with Background Bleed

The background of a scanned color document may contain the bleed of thetext on the opposite side of the printed page. In other words, the texton one side of the document may be visible on the other side of thepage, where it may be picked up by the scanner. Generally, we do notwish to keep this information and consider it a visible distortion whichshould be removed from the page. Our method of removing this bleed andrestoring the background to its proper color is as follows:

Run a gradient detector with non-maxima suppression on the entire image,and combine neighboring gradient points into connected gradientcomponents. If all the gradient points of a given gradient component arevery weak (compared to the median gradient component of the image), andif thresholding the color component contained in the gradient componentresults in a connected component whose color is only slightly darkerthan the rest of the background, we have identified a likely backgroundbleed. We can then remove these components from the background, and fillthem with the surrounding background values, as explained below in thesection entitled “Method to re-construct background layer afterforeground has been lifted using neighborhood substitution.”

Method to Detect Smoothly Varying and Textured (e.g., Halftone/ScreenPatterned) Background Region

Texture blocks may be identified as discussed in the section entitled“Method to detect constant halftone and texture blocks,” combined intotexture regions as discussed in the section entitled “Method to detectconstant halftone and texture regions,” and smoothly varying backgroundsmay then be sought as discussed in the section entitled “Method todetect smoothly varying (non-textured) background regions.”

Solving for Foreground Mask

Solving for Foreground Text

In an example embodiment of the present invention, the system and methodmay first group things that probably have text and then threshold later.

The system and method may lift the background regions, e.g., detected asdescribed in the sections above entitled “Method to detect constantregions” and “Method to detect constant halftone and texture regions,”leaving non-background regions of color, e.g., varying or constant. Thesystem and method may combine them into connected components and proceedto analyze them. All connected components with height less than a heightthreshold Th and with a width less than a width threshold Tw may belabeled as likely foreground text components.

Solving for Foreground Line Art

Even if the connected components do not meet the thresholds of discussedin the section entitled “Solving for foreground text,” the system andmethod may still look at the ratio of the greater of the height andwidth to the lesser of the height and width. If max(height,width)/min(height, width)>Gr or a ratio of an area of on pixels tobounding a box size surrounding the component is less than Rt, thenthese components may be considered as likely foreground line artcomponents.

Detecting Text Lines

Likely foreground text components extracted as described in the sectionentitled “Solving for foreground text” can be grouped together intowords as follows:

The image is divided into k×k grid cells. Each cell of the grid subtendsan x-y range in the image and contains a list of all the components thathave their centroid located inside the grid cell. Then each componentlooks at every component in the component list of its own grid cell andits neighboring grid cells. The component links to the closest componentthat is collinear to itself.

One method to determine if two components are collinear is if they sharethe same top and bottom runs, where a top run has no run on above it,and a bottom run has no run below it.

In the second pass, all the linked components are checked to see if theyform collinear lines and are grouped together as tlines, likely textlines. Components on the tlines are sorted using their left bounding boxcorner and stored in that order.

Detecting Words

To group components into words, for each tline we obtain the distancebetween the bounding boxes of each component. We histogram thesedistances and look for two prominent peaks. The smaller of the two peakdistances is labeled the inter-letter distance and the other peakdistance is labeled the inter-word distance. We revisit all thecomponents on the text line and group all the components together inwords that are less than the inter-word distance away from each other.

This histogram curve can alternatively be modeled as the combination oftwo Gaussian probability distributions, where we solve for theparameters of each distribution.

Detecting Constant Color Text Regions

All lines that either have approximate same starting point or sameending point are grouped together. We sort the lines using their bottomcorner point. We then compute the interline distance. The interlinedistance is used to break the current regions into one or more regionsif necessary. The smooth local symmetry (SLS) axis of each connectedcomponent in the text region is computed and, using only the points oneach component's SLS, we determine the component's median color value inYCbCr space. A color median of all component color medians is thencomputed (regionColorMedian). All tlines with the same starting point orending point, i.e., left or right margins, consistent interlinedistances, and low color variance with respect to the regionColorMedianare grouped together as a likely constant color text region.

Method for Handling Undersampled Documents (Such as Below 50 dpi) fromHandheld and Other Low Resolution Devices—Method for Upsampling ofUndersampled Documents Prior to Lifting Foreground

In an example embodiment of the present invention, the system and methodmay detect low resolution lines. For the detection, the system andmethod may, with respect to the non-background connected componentswhich have been grouped together into word and line components, asdescribed above, analyze whether a text height is smaller than somethreshold. If it is smaller than the threshold, the system and methodmay determine that it is undersampled. If it is undersampled, then thesystem and method may increase the component's height by some multipleso that it is at least the correct height which can be used (themultiple may result in a size greater than the threshold). Once it isupsampled, thresholding may be performed.

Accordingly, for undersampled document images, especially those sampledat cell (handheld) scan rates, special methods may be used to preservetext readability. First, the background region needs to fit a model,such as constant color. Using region growing, as described in thesection on segmentation, the background region is “fit” to the image,and pixels not fitting this background model are left on the image.These pixels may then be grouped into connected components. Theseconnected components may be analyzed using characteristics includingarea, bounding box height and width, color constancy, and collinearityto determine if they are likely to be text components. Likely textcomponents may be grouped into line structures. Using characteristics ofthe line, including line height, the text line may be labeled as regularor undersampled.

Text lines labeled as undersampled may be grouped into largerundersampled text regions. Undersampled text regions are those where thetext is sufficiently small such that readability will not be preservedusing MRC compression unless the image is upsampled prior tocompression. The undersampled text regions may be analyzed to determinethe degree of image upsampling required to preserve readability. Amethod to compute the upsampling scaling factor S that preservesreadability is to determine for each image text region Ri the mediantext height Hi, i.e., the median height of all components in text regionRi. The system and method may then take the smallest text heightHmin=Min(Hi) and find the scaling factor S that preserves readability ofthis region after thresholding. This scaling factor S may be computed tobe the value that resamples the image such that Hmin is greater or equalto some value, typically either 8, 10, 12. The entire image may then beupsampled by scaling factor S using an integer approximation of bicubicspline interpolation.

Regarding the upsampling in the case of low dpi grayscale or colorspace, in order for the upsampling to allow for the thresholding, wordconnected components may be grouped together, rather than characterconnected components. Accordingly, the system and method may upsamplethe image such that even the smallest font can be topologicallypreserved under thresholding.

Once upsampling has been performed, a thresholding method different thanthat discussed below and which is specific to low dpi space may be used.

Method for Detecting Picture Regions

Images are usually made of background, text, line art, and/or pictures.In this regard, MRC coding allows for multiple layers to be encoded onthe same page. The layers typically include a mask layer (which containstextual information and line art), a foreground layer (which colors themask), and a background layer (which appears beneath the mask). Whilethese separate layers are ideal for color business documents, there aretimes when it pays to encode a region separately in its own layer, as inthe case of pictures. Normally the background layer of an MRC file isencoded in low dpi, which lessens the details. For the background of abusiness document, such encoding is usually fine. If however there is apicture somewhere on the page, it may be desirable to maintain thehigher resolution rather than to lower the resolution of the picture andlose precision. A method is therefore needed to detect such pictureregions, and to determine how best to encode them, which will frequentlybe in a separate layer from the rest of the document.

Above, detection of background, text, and line art has been described.In an example embodiment of the present invention, once those elementshave been detected, the system and method may label the remainingregions as pictures.

Accordingly, the first step to detecting picture regions in a documentis to remove all non-picture elements from the page. Every pixel in theimage can be categorized as belonging to a layer of the MRC compression.Any pixels which will be encoded in the mask layer can be considered asa part of an element of the text or line art. The textual and line artelements, the texture regions, as well as the constant color backgroundflat regions may therefore be removed. Anything which remains can beconsidered as a likely picture region.

Method for Lifting Text on Picture Regions

In an example embodiment of the present invention, the system and methodmay lift text in picture regions only if the text forms a well behavedtext line.

Minimizing Lifting Non-Text Elements on Non-Picture Regions

In an example embodiment of the present invention, the system and methodmay refrain from lifting small components in the foreground color layerif they do not form a collinear text line.

Efficient Gradient Computation by Avoiding Smooth Regions

Using detection of gradient points, i.e., edges, is a powerful tool todetect foreground textual and line art components. While an excellenttool for picking up text, gradients are computationally expensive andshould be applied only where necessary.

Gradient computation can generally be avoided when the backgroundsurface is modeled precisely, as in constant color background. Even whenthe background surface cannot be modeled by a single constant color, thesystem and method may provide that the gradient is computed only asneeded and not for the entire image (e.g., not in those sections wherethe smoothed version of the section matches closely to a single constantcolor). This may provide the accuracy of gradient detection with thespeed of much faster methods like static thresholding.

In an example embodiment of the present invention, the system and methodmay accordingly perform the following algorithm. For each flat regionthat is detected, the system and method may refrain from computinggradient information at any pixel that is part of the flat region.

Otherwise (if the region is not of a constant color), the image may bedivided into k×k cells. The system and method may compute the variancefor each cell. If the cell variance is less than some threshold Vb,e.g., 30, 50, or 70, then the system and method may refrain fromcomputing the gradient for the pixels in the cell and may assume thereis no relevant edge information for segmentation.

If the variance is above Vb, but is still fairly low and is below asecond threshold Vb₂, the cell may be divided into four subsections.These subsections may be the four quadrants, four vertical strips orfour horizontal strips. If the mean color and variance of all thesubsections are similar, then the cell may also be excluded fromgradient computation.

Otherwise (if the cell variance is not less than the threshold Vb, or ifeither the cell variance is not less than the threshold Vb₂ or thevariance of the subsections aren't similar), the system and method mayuse gradient point detection for detecting foreground textual and lineart components, so that such use of gradient point detection forforeground textual and line art components may be performed conditionalupon these conditions.

Selective Removal of Maximal Gradient Points

While maximal gradient points can be useful for finding the boundary oftext components, they may also result from texture and noise. Treatingsuch non-textual and non-structural gradient points the same as textualand structural gradient points may result in lifting texture and noiseto the mask layer, which will obfuscate it and reduce the clarity of thetext. Therefore, once the gradient points for a k by k cell have beenfound, the system and method analyzes the properties of the maximalgradient points.

Each maximal gradient point is classified based on its eight8-neighbors. If none of those 8-neighbors are themselves maximalgradient points, the maximal gradient point is classified as asingleton. If only one of its 8-neighbors is a maximal gradient point,it is classified as an endpoint. If two of its 8-neighbors are maximalgradient points and they are adjacent to each other, it is alsoclassified as an endpoint. A k-junction is calculated as follows: Startfrom the top right 8-neighbor and traverse the eight 8-neighbors in aclockwise direction until the top 8-neighbor is reached. At each step inthe traversal, if a move is made from a maximal gradient point tonon-maximal gradient point, a counter is incremented. If at the end ofthe traversal the counter has a value greater or equal to 3, the pixelis classified as a k-junction.

The complexity of the cell is determined in part by whether it has somecombination of too many endpoints, too many singletons, too manyk-junctions, or too many maximal gradient points. If a given cell is nottoo complicated we proceed to the next step (maximal gradient connectedcomponents), which will be explained in the next section.

If however a cell is too complicated, smoothing will be done on thecell. (The extent of the smoothing may depend on the level of thecomplexity.) New maximal gradient points will then be computed on thesmoothed cell. If the complexity of the cell is below a certainthreshold we proceed to the next section. Otherwise we build a histogramof the maximal gradient points in the cell and look for prominent(well-supported, well-defined) maximal peaks. If there is one dominantpeak, we classify the cell as completely texture, and all gradientpoints in the cell are removed. If there is more than one dominant peak,the lightest (i.e. weakest gradient response) such peak is identified astexture, while the second lightest peak is presumed to represent text.Any maximal gradient point which is closer to the lightest peak than tothe second lightest peak is removed from the cell.

Forming Maximal Gradient Connected Components

In an example embodiment of the present invention, the system and methodmay perform a method of merging into a single gradient component twoseparate components. For example, the gradient component of an ‘o’ mayinclude in an inner circle and an outer circle, which may be merged intoa single component.

Once all the gradient maxima pixels on an image have been computed, thesystem and method may form their connected components. After finding thegradient connected components, certain overlapping components may bemerged together, where components overlap if their bounding boxesintersect. For example, the system and method may merge together thecontours of certain components with holes, such as the letter ‘O’, aswell as contours of other components which may have been broken intopieces due to several boundary pixels that have weak gradients. If thedegree of overlap of the bounding boxes of the two components issufficient, then the system and method may merge them.

These connected components may then be analyzed and labeled as eithertext or line art, according to the methods discussed above. Thesegradient components may then be used to provide a set of intensity-basedconstraints used for thresholding, which is discussed below.

Using Gradient Ribbons for Segmentation

There are various criteria for determining within a likely text regionwhether a gradient component is text or line art, both of which need tobe lifted into the MRC text (mask) layer, or whether it is texture,which should be left on the background layer.

One such method makes use of the gradient component ribbon width.Determine the region ribbon width by traversing the all the gradientcomponents in the region in raster scan order, measuring the number ofpixels between each pair of ascending and descending gradient pixels,and adding that value to the set of widths found. The median width ofthese values (alternatively the mean or mode) is considered to be thegradient region ribbon width. Having determined this median ribbonwidth, only components of approximately this width are labeled as textand lifted to the mask layer.

Another implementation would only include pairs of ascending anddescending gradient pixels whose tangent directions match.

Fusion of Gradient and Model-Fitting Methods for Improved Segmentation

General Thresholding Methods Segmentation-Based Thresholding Methods

Method to Threshold Components Using Gradient Components

Thresholding is differentiation between foreground and background,generally by picking a threshold value for the determinations.

Gradient point may be measured. For example, if the foreground is blueand the background is yellow, then at the boundary point, there will bea sharp change in color, and therefore a strong gradient response. Thesystem and method may mark those points as gradient points.

Once the gradient points are obtained, the system and method may findconnected components of gradient points, which may be assumed to trace aboundary of an item. The system and method may then pick a singlethreshold value for the entire item connected component based on thevalues of the gradient points.

The system and method may threshold every gradient component which hasbeen determined to be textual or line art, thereby forming a foregroundcomponent.

Every gradient point in the gradient component may be assumed to be onthe boundary between the foreground and the background. The system andmethod may therefore determine the parallel direction to the gradientdirection, i.e., the tangent direction, and pick one pixel on each sideof the considered gradient point pixel in the parallel direction, asshown in FIG. 1, one of which it is assumed will be darker than theother. The system and method may label the lighter of the intensityvalues Pi_L and the darker of the intensity values Pi_D, and place thesetwo values in separate arrays, each array including a plurality of likevalues (i.e., either Pi_L or Pi_D) for each of the pixels of theconnected component. Accordingly, assuming there are N gradient pointson the gradient component, there may therefore now be a corresponding Npairs of lighter and darker points (which will tend to be the interiorand exterior points). That is, the sets of points may include S_L={P1_L,P2_L, . . . , PN_L} and S_D={P1_D, P2_D, . . . , PN_D}.

Next, the system and method may take vL=min(S_L) (the value in the lightarray that is the darkest, i.e., it has the smallest of the light arrayvalues) and vD=max(S_D) (the value in the dark array that is thelightest, i.e., it has the greatest of the dark array values). It isnoted that the light color values are greater than the dark colorvalues. For example, black is 0 and white is 255.

If vL>vD (meaning the two sets do not overlap) then all the gradientconstraints yield a consistent intensity solution (that is, any valuethat is above the lightest of the dark and below the darkest of thelight, e.g., the average of the two, can be used as the thresholdvalue). Accordingly, the system and method may, in this case, selectthreshold t=(vL+vD)/2 as the intensity threshold for the component.However, this is usually not the case. Accordingly, if vL<=vD (meaningthere is an overlap), we find which rank r values vL_r (the rth min ofvL) and VD_r (the rth max of vD) are such that vL_r>vD_r. If r>95%, thenthe system and method may select threshold t=(vL_r+vD_r)/2.

If for rank r=95%, it is still the case that vL_r<=vD_r, the system andmmethod may consider this as indicative of either 2 or more foregrounds,2 or more backgrounds, or an undersampled text region, so that thesystem and method may refrain from selecting a threshold using thismethod.

Method to Threshold Words Using Gradients

Every letter should have its own gradient curve. The system and methodmay find a first threshold for one letter and a second threshold foranother letter. However, it is also possible to get multiple curves in aword and then calculate a single threshold value for the entire word,and even for an entire line (line is discussed in the next section). Thethresholds determined for such larger regions may be more reliable thanthose for individual letters.

In an example embodiment of the present invention, such thresholddeterminations for larger regions may be performed using a methodanalogous to that discussed above in the section above entitled “Methodto threshold components using gradient components.” However, thethreshold values may be found for each word instead of merely for eachindividual component. The word gradient component used to threshold aword may be the union of all the gradient connected components that formthe word.

To determine which groups of gradient components are of a single word,the system and method may find the distance between gradient components.For large distances, it can be assumed that the components are ofdifferent words; for smaller distances, it can be assumed that thecomponents are of a single word. This is just one exemplary method forfinding those components of a single word.

Once it is known that components are of a single word, the system andmethod may generate the arrays discussed above, i.e., a single darkarray S_D and a single light array S_L for all the gradient componentsof the single word. Using these arrays, the system and method maydetermine the threshold value according to the method described above inthe section above entitled “Method to threshold components usinggradient components” with respect to the individual components.

If a value that would satisfy the word as a whole cannot be found, e.g.,for rank r=95%, it is still the case that vL_r<=vD_r, then the systemand method may attempt it for the components locally.

Method to Threshold Lines Using Gradients

Similarly, in an example embodiment of the present invention, the systemand method may select threshold values on a line basis, instead ofmerely for individual words or components. The line gradient componentused to threshold a line may be the union of all gradient connectedcomponents that form the line. Whether the line, the word, or theindividual component is used, may depend on whether a satisfactory valueis found.

Method to Threshold Text Regions Using Gradients

Similarly, in an example embodiment of the present invention, the systemand method may select threshold values on a text region basis, where thetext region encompasses more than individual lines. The text regiongradient component used to threshold a text region may be the union ofall gradient connected components that form the text region. Whether theregion, the line, the word, or the individual component is used, maydepend on whether a satisfactory value is found.

Thus, the system and method may find the largest component (e.g.,region, line, word, or individual component) for which a satisfactoryvalue can be found.

Method to Threshold Large Structures Using Gradients

With a very large component or structure, such as a grid, the system andmethod may threshold each k by k cell individually, and not the entirecomponent together. Each k by k cell will be treated as a separatecomponent for verification purposes as well, as will be described in thenext section.

Method to Verify Gradient Threshold Correctness and Determine ComponentPolarity

After finding a threshold value, the system and method of the presentinvention may determine which side of the threshold value belongs to theforeground layer and which side of the threshold value belongs to thebackground layer.

In an example embodiment of the present invention, after the system andmethod determines the threshold value, e.g., using the gradientcomponents, the system and method may apply the bounding box around thegradient component in the gradient image to the same position in theoriginal image. The system and method may apply the threshold to thebounding box applied to the original image, such that, for each pixel inthe bounding box, if the pixel's value is greater than the thresholdvalue, the system and method may assign to the pixel a value of 1, forexample, and otherwise, a value of 0.

To auto-check that the selected threshold value is a good one, thesystem and method may, e.g., using the Hausdorff rank 95 matcher, matchthe new component just created using the threshold value in the boundingbox to the corresponding gradient component of the gradient image fromwhich the bounding box was obtained.

If there is a match, it may be assumed that the threshold was correctlyselected and that the polarity (which side of the threshold value isforeground and which side of the threshold value is background) iscorrect since, if the background had been treated as foreground and viceversa, then the match would likely not have been found.

If the match fails, the system and method may reverse the polarity andre-perform the matching. (Alternatively, the system may match bothpolarities in all situations and select the better of the two.)

If the match fails even after revering polarity, then it can be assumedthat either the selected threshold was wrong or there is no thresholdvalue that can be used. The system and method may therefore determinethat this gradient component should not be thresholded by default.

Accordingly, the threshold determining methods described above using theS_D and S_L arrays assume that the gradient component has a consistentsolution in that the interior pixels of the gradient component have aconstant color and that the exterior pixels have an intensity that iseither consistently lighter or darker than the interior pixels. Aconsistent solution to those methods implies a Hausdorff or rankHausdorff match (rank 95) of distance 1 between the image gradientpoints and the thresholded intensity boundary points, assuming that thepolarity is correctly solved for. Polarity is defined as video if thedarker points are thresholded to foreground and reverse video if thelighter points are thresholded to foreground.

The system and method can determine the polarity of a thresholdedcomponent by checking which polarity value, video or reverse video,yields a greater rank Hausdorff match, where the greater rank is givenby r_p. The rank r used to find a consistent threshold t, as in themethods described above using the S_D and S_L arrays, is already known.If r=r_p then it is assumed that the polarity of the component has beencorrectly determined and that the correctness of the threshold value hasbeen verified.

Testing for Non-Color-Constancy Using the Non-Matching of Gradient andIntensity Constraints

If the gradient map and the intensity map within the bounding box do notmatch when performing the matching with respect to both polarities, thenit may be assumed that there is not a constant color in the section andthat a threshold value cannot be used. Instead, the system and methodmay keep the section in the background layer, i.e., it will not belifted into the foreground layer and may have a reduced resolution.

A consistent solution of the gradient component's intensity constraints,as described above with respect to the S_D and S_L array methods,reinforces the MRC model of constant background text on a slowly varyingsmooth background region. An inconsistent solution implies that the MRCmodel is not locally applicable. One such reason for the inapplicabilityof the MRC model is foreground non-color-constancy. When no consistentsolution is found that is rank 95% or above, it implies that either theforeground is not an approximately constant color or that the backgroundis not an approximately low-frequency smoothly varying surface.

Method to Detect/Threshold Text on Texture

In an example embodiment of the present invention, where there is atextured background, a variation of the thresholding method can be used.First, the system and method may determine whether the background istextured, e.g., as discussed above in the section entitled “Method tofind halftone screens and texture before smoothing,” which may includecomputing the gradient components.

In an example embodiment of the present invention, the system and methodmay always smooth texture before lifting the text on texture regions. Ifthere is texture, then the region may be smoothed and then the gradientrecomputed.

The system and method may check for two peaks in a histogram of therecomputed gradient. The histogram may show the intensity values, wherethe greater the value, the greater the gradient, for example, along thex axis, and may show along the y axis the number of pixels having thegradient value plotted along the x axis.) The peaks are the two greatestvalues plotted with respect to the y axis and correspond to the twointensity values shared by the greatest number of pixels in the region.The peak with the weaker gradient strength is assumed to be texturedbackground. Those pixels having that value may then be eliminated fromthe gradient points.

If only one peak exists and most of the points of the block are weakerthan some threshold, then it may be assumed that the entire region hasonly textured background, so that all of the points of the region areeliminated from the gradient map.

That is, the gradient strength of texture is usually weaker than thetext strength. An image may be divided into k×k cells. The system andmethod may look for all the cells in a texture region that have twodifferent prominent gradient strengths. For such cells, the system andmethod may eliminate weaker gradient points if they don't form anysignificant smooth structure. The system and method may lift strongergradient points as text components if they form well-behaved smoothcurves.

Method to Determine Component Polarity Assuming a Flat Background

In an example embodiment of the present invention, where there is a flatbackground, the system and method may generally refrain from calculatinggradient components, as described above.

But, in example embodiments of the present invention, the system andmethod may calculate gradients and perform the thresholding methodsdescribed above using the S_D and S_L arrays. In such cases, as analternative to determining polarity using the Hausdorff matcherdescribed above in the section entitled “Method to verify gradientthreshold correctness and determine component polarity,” the system andmethod can use the following method.

Using the computed threshold t, the system and method may partition theintensity pixels in the bounding box corresponding to the gradientcomponent into two sets sD and sL, where sD is the set of darker pixelsand sL the set of lighter pixels. The system and method may compute mDand mL as the means of sD and sL, respectively and compare mD and mL tothe background mean mB. If |mL−mB|<=|mD−mB|, then the system and methodmay determine that the component polarity is video and, otherwise, thatit is reverse video.

Method to Threshold Components Using Flat Background and Gradients

In an example embodiment of the present invention, the system and methodmay perform a method that combines the features of the S_D and S_L arraymethods and the method described in the section entitled “Method tothreshold components using assuming flat background.”

Matching & Refinement

Method for Using Perceptually Lossless Bitonal Mask Layer

All of the features for perceptually lossless bitonal compressiondescribed in the document entitled “Computer Vision-Based Methods forEnhanced JBIG2 and Generic Bitonal Compression,” the entire disclosureof which is incorporated herein by reference and which is attachedhereto, can be used for the mask layer of an MRC image.

Encoding

Pushing Every Component to a Single Constant Color, Wherever Possible

With respect to foreground, a goal is to get a component to a singlecolor. The original image may include other colors at the borders, forexample. So in an example embodiment of the present invention, thesystem and method may get rid of this.

Every pixel in the foreground mask may have a color value associatedwith it. The values of those pixels on the boundary are not of muchinterest. Accordingly, the system and method of the present inventionmay break components into interior and exterior points. If there aresufficient interior points, the system and method may ignore theexterior points.

Accordingly, once the foreground in segmented into components, thesystem and method may choose the appropriate color for each of thesecomponents. If a component has sufficient interior pixels, the systemand method may place the interior pixels into a sorted vector based onintensity and analyze them to see if whether the entire component can bepushed to a single color.

The analysis may be performed in the following manner. The system andmethod may calculate a chosen Rth, e.g., 90^(th), percentile darkest andlightest pixels. If the intensity difference between these two pixels isdetermined to be less than a threshold T, e.g., 80, and if the intensityvariance of all the interior (non-boundary) pixels is determined to beless than a threshold V, the system and method may responsively choose asingle color to represent the component. This color may be set as themean of all the interior pixels in RGB space. Alternatively, the colormay be set as the median color of the component's SLS axis.

For thin components which don't have sufficient interior pixels, thesystem and method may place all the pixels into a sorted vector based onincreasing intensity and then determine the polarity of the component,for example as discussed above. If the polarity is video, the system andmethod may take all the dark pixels in the bottom Rd, e.g., 10,percentile (the bottom percentile having darker pixels than the higherpercentiles since dark pixels are of a lower value than light pixels).If the polarity is reverse video, the system and method may take all thelight pixels in the top R1, e.g., 10, percentile. The system and methodmay then take the mean value of all these pixels in RGB color space torepresent the component.

Once a single color is found to represent the component, the system admethod may give every pixel in the component that color.

Remap Perceptually Grouped Color Components to the Same Single ConstantColor

Using the method described in the section entitled “Pushing everycomponent to a single constant color, wherever possible,” it may occurthat neighboring components in a document will be pushed to slightlydiffering colors, even when in the original printed document the twocomponents shared the same exact color. To both improve the imagequality of the document and to better improve the compression ratio, itpays to give all such components the same color wherever possible. This,however, can be a risky operation, for if two components are mistakenlypushed to the same color, the image can be distorted. Accordingly, thesystem and method may proceed cautiously in a systematic manner.

In this regard, the system and method may first determine if all thecomponents in a word can be pushed to the same color. If they can be,the system and method may then determine if all the words on a line canbe pushed to the same color. If they can be, the system and method maythen determine if all the lines in a paragraph or region can be pushedto the same color. The following may performed to make thesedeterminations.

With respect to pushing all the components of a word to the sameconstant color, the system and method of the present invention may firstgroup components into words and then determine if the components of theword can all be pushed to a same constant color. That is, the system andmethod may, for each word, extract all of the word's components whichhave already been pushed to a constant color. Any component of the wordwhich had not been pushed to a constant color will be ignored in thisoperation, and will be left with its multitude of colors. The system andmethod may create a sorted vector (in intensity space) of the colorsfound in the various considered components of the word. In one exampleembodiment, the system and method may place in the vector only one pixelfrom each of the considered components. In one example embodiment,pixels from very small components may be left out of the vector. (In analternative example embodiment, the system and method may place everypixel of all of the components, including the small components, in thevector. In yet another alternative example embodiment, the system andmethod may place more pixels from the larger components into the vectorthan from the smaller components, where the number is not necessarilyfully proportional to the number of pixels in the component.)

The system and method may take the median pixel of this vector andcompare each component's color to the median. For those that are at adistance greater than some threshold, those components' colors may bemaintained. The system and method may compute the median of theremaining components and use its color to represent the whole word,e.g., but for those having colors that are to be maintained.Alternatively, the system and method can use the initial computed medianto represent the whole word, but for those having colors that are to bemaintained. In one embodiment, the pushing of the remaining componentsto the median may be performed conditional upon that less than a certainpercentage of the components were found to have been further than thethreshold distance from the median.

The same method used to push all the components in a word to the samecolor value may also be used to push all the words in a line to the samecolor value. Alternatively, where there is no word information, thesystem and method can directly push all the components in a line to thesame color using the same method. The system and method can frequentlythen proceed from the line level to the region level, thereby pushingall the lines in a region to the same color.

Utilizing Multiple Foreground Maps

With MRC compression, the foreground is generally represented bycombining the information of two layers. The mask layer determines whichpixels will be in the foreground, while the color foreground layerdetermines how to color the pixels of the mask layer. In order to savebytes, the foreground color layer is usually represented by a low res(resolution) image, which is typically an 8 to 1 reduction from theoriginal image. A problem arises when two very different colors are inclose proximity within the foreground layer. This can be especiallytroubling when some pixels are video and other pixels are reverse video,and they both neighbor each other in the mask. In fact, it can evenoccur that these two very different colors are meant to both berepresented by the same foreground low res color pixel. This would meanthat at least some of these pixels will be represented by a veryinappropriate color value.

Embodiments of the present invention provide several ways of identifyingsuch problems and resolving them. These techniques include computing theforeground color gradient or variance. Then, if the variance is greaterthan some threshold for some local region (e.g., a region correspondingto a single pixel in the foreground low res color), the system andmethod may spawn multiple foreground layers to resolve this problem.

In an alternative example embodiment of the present invention, toresolve multiple foreground colors in proximity, the system and methodmay upsample the foreground image color layer iteratively, by a factorof 2 in each iteration, until the resulting color gradient or varianceis below a given threshold. For example, instead of having a singlepixel of the foreground layer representing an 8×8 of the original, itwill represent only a 4×4 after the first iteration.

Eliminating Flat Background when MRC Coding

When a rectangular flat region of background pixels share a similarcolor (flat means share a similar color within a certain tolerance ofeach other), the system and method can push all the pixels in thatregion to the same color, e.g., the mean color of the pixels. Whenwriting PDF files, for example, instead of then encoding that region asan image within MRC, the system and method can use a PDF command topaint the region with that color.

Method to Remap Color Scans of Black/White Images to Black and WhiteImage Format

Frequently a grayscale image will be scanned in color mode, which maythen misinterpret some pixels as having values other than grayscalevalues. In an example embodiment of the present invention, the systemand method may identify such situations, may identify all the pixels inthe foreground, and may remap all the pixels in the foreground tograyscale values, thereby saving bytes and improving image quality.

The system and method may do this by determining whether all of thepixel values in the foreground layer are within a tolerance of agrayscale value. If they are, the system and method may push all thosepixels to the nearest grayscale value.

Similarly, when a Black and White image is scanned in color or grayscalemode, some pixels may be misinterpreted as having values other thanBlack and White. In this case, the system and method may remap allpixels to a Black or White value. To do so, the system and method maydetermine whether all of the pixel values in the foreground layer arewithin a tolerance of a black or white value. If they are, the systemand method may push all those pixels to the nearest black or whitevalue.

In fact, whenever a document contains only two colors, the system andmethod may both save bytes and improve image quality by pushing all thepixels in the foreground to one of those two colors, for example bychoosing the mean of the background and foreground colors and testingwhether the distance of the values of the pixels are within a thresholddistance from the mean value. Alternatively, for the foreground, insteadof using the mean as with the background, the median color may be used.

Method to Re-Construct Background Layer after Foreground has been LiftedUsing Neighborhood Substitution

In MRC compression, the foreground layer is placed above the MRCbackground layer. Even when the foreground pixels have been removed fromthe image, a value is still needed for those removed pixels even in thebackground layer. Leaving those pixels with the value of the foregroundpixels may lead to blurring artifacts that can hurt the readability ofthe image because of the nature of compression algorithms that may beused to encode the background layer.

Accordingly, in an example embodiment of the present invention, thesystem and method may determine the value for those pixels in thebackground layer using the following algorithm.

The system and method may dilate the mask pixels by one for computationpurposes. To do so, the system and method may find all of the boundaryblack pixels. A boundary black is where the pixel is black and one ofits neighbors is white. The system and method may center each boundaryblack pixel in a 3×3 cell and paint the rest of the 3×3 cell also toblack (some might already have been black in the original mask). Anypixel of the original image which now corresponds to positions coveredby the dilated mask may have its original value removed. The system andmethod may then proceed in raster scan order and give each of those“removed” pixels a background color value which is the average of allthe previously visited ones of the considered pixel's neighboringbackground pixels (meaning the 4 preceding neighbors—three above and oneto its left—and any other of its 8 neighbors which did not fall within adilated pixel and which therefore retains its background color value).This new value may be considered as an original background pixel valuefor all subsequent pixels. The system and method may then proceed in asecond pass in the reverse raster scan order (bottom up, right to left),revisit each of those pixels, and give them the average of the values ofall its neighbors and the considered pixel's previously assigned valueas calculated in the first pass.

Method for Color Spreading of Foreground Layer for Better Compression

Similarly, the same can be performed with respect to filling in thoseportions of the foreground layer for which the mask layer does notinclude corresponding pixels. That is, the same problem arises for theforeground layer for the reverse reason of the background layer.

In the foreground color layer, each pixel represents a k×k number ofpixels in the mask, since the foreground layer is a low res layer. Thecolor of that pixel should be the one which best approximates the colorof the high res pixels in the image which were included the mask.However, it is possible that a pixel in the foreground color layer maynot have any mask pixels within the k×k region that it represents. If atleast one of the pixels of the corresponding k×k in the mask is of theforeground, then the at least one pixel's value can be used for thecolor in the corresponding single pixel of the foreground layer.

In such a situation the system and method may give a color to thosepixels both to improve image quality and to save bytes. Leaving thosepixels as white may distort the color of those pixels which neighbor it,and will require the expensive jpeg costs of transition from a color towhite and then back again.

To assign the colors, the system and method may use the same algorithmdiscussed above with respect to filling in the background layer. Thesystem and method may proceed in raster scan order to give each emptypixel the average value of its visited neighbors, etc.

Method for Determining when to Merge, Split, or Drop (Into Background)Foreground Color Clusters

In an example embodiment of the present invention, even when a text hasbeen properly identified and lifted into the foreground, the system andmethod may, at times determine that, for compression purposes, it paysto leave the text in the background, and may accordingly do so. Forexample, if the mean stroke thickness of the text is great enough, thesystem and method may drop the text into the low res background layerwithout at all affecting image quality. As the mask layer can beexpensive, such a method to decrease the number of pixels in the masklayer may be worthwhile.

Terms

Gradient

The gradient of a pixel is a measure of how quickly the valuesneighboring the pixel are changing in each of the four directions:horizontal, vertical, left-diagonal and right-diagonal. Theleft-diagonal goes from the top left to the bottom right, and is thediagonal with a negative slope. The right-diagonal goes from the bottomleft to the top right, and is the diagonal with a positive slope. Thosepixels which neighbor a sharp change in the image, such as those on theboundary of a textual component, may have a strong gradient response,while pixels in a completely constant color region may have no gradientresponse and those in a smoothly varying region may have a very slightgradient response.

Maximal Gradient Points

The gradient of a pixel is calculated in four directions (horizontal,vertical, left-diagonal, and right-diagonal) and the direction with thestrongest gradient is chosen, with that greatest gradient value assignedto the pixel. We then check the gradient value of the two neighboringpixels in the chosen direction. For example if the horizontal directionis chosen, the pixel to the right and the pixel to the left are bothchecked. If the left-diagonal direction is chosen, the pixel to the topleft and the pixel to the bottom right are both checked. Only if thepixel has a greater gradient value than its two neighboring pixels inthe chosen direction can it be considered a maximal gradient point.Since non-maximal gradient points are generally removed, “maximalgradient points” in our invention may occasionally be referred to assimply “gradient points”.

RGB, Intensity

MRC coding can be useful for both color and grayscale images. With colordocuments, there can be three bytes for each pixel, with one byte eachfor the red, green, and blue values. This is commonly referred to as RGBspace. Some of the image analysis techniques commonly used for MRCcompression can be very CPU intensive and may run very slowly in RGBspace. It can therefore pay to transform the image to grayscale foranalysis purposes, and deal with the color values at a later point. Atransformation used for this purpose is intensity space, which measureshow dark or light each pixel is. A common formula used to convert asingle RGB pixel to its intensity value is: V=(30*R+59*G+11*B)/100.Black pixels have an R, G and B of 0, and therefore have an intensity of0. White pixels have an R, G and B of 255, and therefore have anintensity of 255. Darker pixels have a lower intensity value thanlighter pixels.

Variance

Variance refers to a measure of how different a range of values are fromeach other and may also refer to Mean Square Error.

Smooth

Smoothing is when you give each pixel a value that is the determined bya matrix of its neighboring pixels. A common smoothing technique is aGaussian blur, which uses a Gaussian distribution with radius R tocalculate the percentage of the value a pixel gets from each of itsneighbors within the radius.

Halftone

Halftone is the use of black and white to simulate grayscale values,often by use of a dithering pattern. Halftoning may also allow simplercolors to simulate more complex colors.

Texture

Texture can refer to repeated patterns which appear in the background ofthe image, which can sometimes give the 3D illusion of the pagecontaining depth. Texture can refer to a pattern of colors to providethe appearance of a single color.

Downsample

To resample a region by lowering the resolution and giving each new lowres pixel a value which is the average of the high res pixels itrepresents. The reverse operation is called upsampling.

Polarity

Dark text components on a lighter background has regular polarity. Lighttext components on a darker background has reverse polarity, which iscommonly called reverse video.

Thresholding

Selection of a threshold value for determining which pixels to turn ONand OFF in the mask layer. Determination of what pixels get turned ONand OFF can be determined by a combination of the threshold value andpolarity. With regular polarity, those pixels below the threshold areturned ON. With reverse polarity, those pixels equal to or above thethreshold value are turned ON.

In summation, an image may be segmented into a foreground layer, abackground layer, and a mask layer. The mask layer may be used todetermine which pixels are to be assigned pixel values of the foregroundlayer and which pixels are to be assigned pixel values of the backgroundlayer. The foreground and background images may be of low resolution,while the mask layer may be of high resolution. The high resolution maskmay then be used to reconstruct the image at high resolution using thevalues of the background and foreground images.

Example embodiments of the present invention provide for use of gradientpoints for determining the mask layer. However, use of gradient pointspotentially slows down processing time. Therefore, in an exampleembodiment of the present invention, the system and method may initiallyperform preliminary steps to determine whether to implement the processwhich uses the gradient points.

Accordingly, a method for constructing a mask layer of an image mayinclude the following steps.

At step 100, the system may convert an input image into a grayscaleimage. At 102, the system may generate a histogram plotting, for each ofa plurality of pixel values, the number of pixels of the grayscale imagehaving the value. For example, the image may have pixels whose valuesrange between 0 and 255. Each of values 0 to 255 may be plotted, and,for each plotted value, the histogram indicates the number of pixels ofthe grayscale image having that value.

At step 104, the system may determine the peak of the histogramrepresenting the value having the greatest number of pixels to which anysingle value is assigned. At step 106, the system may determine whetherat least a predetermined percentage (e.g., a majority) of the pixels areassigned values that fall within a predetermined range of the determinedpeak value. For example, the predetermined percentage may be 50% and therange may be those values that are within 15 below and above the peakvalue. For example, if the peak value is determined to be 70, the systemmay determine whether at least 50% of the pixels of the grayscale imageare assigned values within the range of 55 to 85.

If it is determined that at least the predetermined percentage of thepixels are assigned values that fall within the predetermined range ofthe determined peak value, then the generation of the mask layer may beperformed without use of the gradient points and using a backgroundsegmentation method, which finds the flat background.

Otherwise, the system and method may use gradient points in an edgesegmentation method beginning at step 108. At step 108, the system maysegment the grayscale image into k by k cells, k being a predeterminednumber, e.g., 32.

For each of the cells, the system may, at step 110, compute the varianceof the cell, where the variance is a value indicating the extent ofvalue change across pixels of the cell. At step 112, the system maydetermine whether the computed variance is at least a predeterminedthreshold value. If the variance is below the threshold value, so thatthe colors of the cell are close in value, the colors will probably beall background or all foreground. Therefore, the cell may be subsumedinto the surrounding cells to obtain their colors at a later step in theprocess, after the colors of the surrounding cells have been determined.

If the variance is above the threshold value, the system may, at 114,determine whether the computed variance is at least a second higherthreshold value. If it is below the second higher threshold value, thesystem may perform further steps to determine whether the cell istexture, e.g., a screening pattern, by analyzing subsections of thecell. Accordingly, at 116, the system divides the cell into subsections.For example, the system may divide the cell into quadrants, into fourvertical strips, and/or into four horizontal strips. At 117, the systemcompares mean color and the variance values of each of the subsectionsto those of the other similarly divided subsections and to the overallcell. This comparison is performed for at least two types ofsubdivisions, and, in an example embodiment, for three types ofsubdivisions, for example, for the quadrant subdivision, the verticalstrip subdivision, and the horizontal strip subdivision.

If, for the compared subdivisions, the respective subsections aredetermined to be within a predetermined range of each other with respectto the compared values, the cell may be assumed to be texture.Accordingly, if they are within the predetermined range, the cell may beskipped and subsumed into surrounding cells, for example, as describedabove.

If the cell is determined, at 114 to be above the second threshold or ifit is determined at 117 that the subsection values are not within thepredetermined range, the system, at step 118, examines each pixel of thecell to determine the cell's gradient points via any suitablyappropriate gradient computation method.

For the computation, the system may compute for every pixel, the pixel'sgradient direction and value. For example, the system may check how thepixel changes vertically, horizontally, and diagonally. For example, tocheck for vertical changes, the system may sum the pixel values of the 3pixels above the subject pixel, including the pixel directly above, thepixel to the above-right, and the pixel to the above-left, and comparethe sum to the sum of the 3 pixels below the subject pixel, includingthe pixel directly below, the pixel to the lower-right, and the pixel tothe lower left. The difference in sums is the vertical gradient for thesubject pixel. The system may do the same for horizontal, taking theright three pixels and the left three pixels. For diagonal gradient, thesystem may consider, for the first diagonal, the sum of the pixelimmediately above the subject pixel, the pixel the immediate left andthe pixel to the top-left and compare the sum to the sum of the valuesfor the pixel to the immediate right, the pixel immediately below, andthe pixel to the bottom right. For the second diagonal, the system mayconsider the sum of the values of the pixel immediately above,immediately to the right, and to the above-right and compare the sum tothe sum of the pixel immediately below, the pixel to the immediate left,and the pixel to the bottom left. Whichever direction for which thesystem computes the highest change, the system may consider to be thepixel's gradient direction. Further, the value of that highest computedchange is the gradient value of the pixel.

After the gradient value and direction of a pixel is determined, thesystem compares the gradient value of the subject pixel to the gradientvalues of the pixels which neighbor the subject pixel in the gradientdirection of the subject pixel. For example, if the gradient directionof the subject pixel is vertical, then the gradient values of the pixelimmediately above the subject pixel and the gradient value immediatelybelow the subject pixel. If the gradient values of either of theneighboring pixels in the gradient direction exceeds the gradient valueof the subject pixel, then the subject pixel is not considered a maximalgradient point and therefore does not remain considered as a gradientpoint. That the neighboring pixels' gradient directions differ from thesubject pixel is not considered. Additionally, if the gradient value ofthe subject pixel is below a threshold, the subject pixel is notconsidered a gradient point. Otherwise, the subject pixel is initiallyconsidered a gradient point, subject to change.

After computing the gradient points for the cell, the system determines,at step 122, whether the cell is overly complex with respect togradients. If overly complex, the system smoothes the grayscale imagewith respect to that cell at step 123 and returns to step 118 tore-perform the gradient computation steps described above as applied tothe new grayscale image with respect to the cell.

For the complexity determination, the system determines for each k by kcell, whether the cell has greater than a certain threshold number ofgradient points, in which case the cell is considered too complex. Thenumber of gradient points may be computed by a weighted combination ofvarious gradient point types. For example, the gradient points mayinclude singletons, endpoints, and k-junction points, different ones ofwhich may be differently weighted when computing the sum of gradientpoints in the cell.

If the cell is found to be complex, the system considers the cell to betexture and smoothes the cell at step 123. The smoothing can be done viaany suitably appropriate smoothing method. The system then returns tostep 118 after the smoothing for re-examination of the cell's gradientpoints according to the method steps described above. After thesmoothing, some of the gradient points may be removed in the next passthrough the steps since smoothing results in weaker gradient points.

If, at step 122, it is determined, whether prior to any smoothing orafter a single performance of smoothing, that the cell is not toocomplex, the system proceeds to step 130.

If after performance of a smoothing, the result of the complexitydetermination at step 122 is that the image is still complex, the systemmay perform the following.

If a cell is still labeled as texture/noisy, the system, at 140,computes the histogram of the cell's maximal gradient points. Thishistogram indicates for each gradient value, the number of maximalgradient point pixels having that value.

At step 141, the system modifies the gradient points of the cell basedon the histogram. The system determines all the dominant peaks in thehistogram. A peak is considered dominant if its peak value is above athreshold P, and it is greater than all of its neighboring values withina distance D, which is frequently 10.

If there is only one dominant peak in the histogram, mostly composed ofweak maximal gradient points, the system removes the gradient pixelsfrom the cell. If the dominant peak is at a high level, then the systemkeeps all gradient points of the cell.

If there is more than one dominant peak, then the system removes allmaximal gradient points closer in value to the weakest dominant peakthan to the second weakest dominant peak. For example, if there is apeak at value 70, which is the lowest peak, and there is a higher peakat value 150, which is the second to lowest peak, then the systemremoves all gradient points below 110.

At step 130, the system forms connected components using the remainingmaximal gradient points. In other words, the system merges connectedgradient points into a single object.

At step 132, the system merges overlapping gradient components (e.g.,middle of letter “o”) and other separated components. In other words, ifthe letter O is thick, the letter will result in a first connectedcomponent of the outer boundary of the letter O and then anotherconnected component which is the inner boundary of the letter O. Look atbounding boxes of the connected components. If they significantlyoverlap, then they will be merged. In this case, the O is completelymerged.

At step 134, the system classifies the connected components (alsoreferred to as gradient components) as text, line art, or noise byexamining the component features, including area, height, width, strokethickness, Euler number (Euler number is the number of holes in anobject, for example), etc. For example, text has certain properties interms of area and height to width ratio, etc., which can be used forthis classification.

After the connected components are determined, the system may generatethe MRC mask image as follows.

The system visits all the gradient components. If component is labeledas a text component, the system thresholds the component using gradientconstraints as follows. Create two histograms, one for lighter pixelsand one for darker pixels. In other words, for the gradient direction ofeach single pixel of the connected component, take each neighboringpixel of the gradient point pixel, one neighbor usually being lighterthan the other neighbor. For example, if the pixel is a gradient pointin the vertical direction, take the pixel above and the pixel below thesubject pixel, one usually being lighter than the other.

Get the intensity value of the two adjacent pixels from the grayscaleimage in the gradient direction, generally perpendicular to the gradientperimeter, and identify which is lighter and which is darker. Label thelighter pixel as L and the darker pixel as D. Proceed to check the pixeladjacent to the lighter pixel L in the gradient direction and away fromthe current gradient point P. If this pixel is lighter than the L, markthis pixel as L. Likewise, check pixel adjacent to the darker pixel D,in the gradient direction and away from the current gradient point P. Ifthis pixel is darker than the D, mark this pixel as D. Place L into thelighter histogram and D into the darker histogram.

After the arrays of dark and light pixels are generated for theconnected component as a whole, subsequently find a threshold T, where Tis the value which maximizes the sum of the number of darker pixelsbelow T, i.e., darker than T, and the number of lighter pixels greaterthan or equal to T, i.e., lighter than or equal to T.

Then, use the value T to threshold the bounding box of the grayscaleimage (also referred to as the intensity space) that corresponds to theconnected component and add the pixels below the threshold (the pixelsdarker than the threshold value) as black pixels in the mask.

If a component is labeled as line art, then, divide the component'sbounding box into k by k cells. If a given k×k cell has any gradientpoints that belong to this component, threshold the cell and update themask image using gradient constraints, i.e., using the neighboringpixels in the direction perpendicular to the gradient perimeter, asdescribed above for text components.

Finally, if a component is labeled as noise, the system does notthreshold it. Instead, it is considered part of the background.

Form thresholded connected components using the obtained mask. For eachthresholded component, the system then decides whether it is correct andshould remain in the mask layer. If it is reverse video, e.g., lighttext on dark background, then the system removes the thresholdedcomponent and places its inverse into the mask layer

To determine whether the thresholded component is correct, the systemthen determines whether the perimeter of the thresholded connectedcomponent fits well with the perimeter of the connected component of thegradient pixels. If there is not a good match, then maybe it is reversevideo. Therefore, the system tries the reverse. If it still does notmatch, then the thresholded component is dropped from the maskcompletely.

Accordingly, the system visits all the thresholded components in themask. The system identifies a component as ‘text’, ‘line art’, or‘noise’ using its area, height, width, stroke thickness, Euler number,etc.

If a component is labeled as text, the system matches each perimeterpixel of the thresholded component with the closest correspondingmaximal gradient point. In other words, there should be a maximalgradient point in the gradient image at a pixel that corresponds to apixel of the component of the mask within distance one. The system triesto find a match in both directions—mask to gradient and gradient tomask. If at least a certain percentage, e.g., 95%, of the component'spixels find a match in each direction, then there is a sufficient matchto keep the mask.

Stated otherwise, determine Pmin, the rank bi-directional Hausdorff,distance 1 metric as the minimum of i). the percent P1 of perimeterpixels that find corresponding gradient pixels within an image distanceof 1 (Euclidean metric), and ii). the percent P2 of gradient pixels thatfind corresponding perimeter pixels within an image distance of 1. IfPmin is greater than some threshold value Pthresh, then label thecomponent as having regular polarity. It may occur that in one directionthe match is below the threshold, e.g., 95% and in the other directionit is above the threshold. This is not good enough. We need bothdirections to be above the threshold percentage. If they are both abovethe threshold, then the system labels the image as regular; not aninverse video image.

Otherwise, the system inverts all the pixels in the bounding box of thethresholded component, i.e., ON switched to OFF and OFF switched to ON.And repeat the above step of computing Pmin. If the recomputed Pmin isgreater than Pthresh, re-label this component as having reverse polarityand invert the mask component.

Otherwise, label the component as non-textual and remove it from themask.

Compute the MRC Background Image

Compute dilation of the mask image.

Remove all the pixels from the original images that are part of thedilated mask.

Fill in the removed pixels with the average color of the surroundingnon-removed pixels.

Reduce foreground image by factor R.

-   Compute the MRC foreground image    -   Visit all the thresholded components        -   If component is labeled as text component, find one constant            color for the component as follows:            -   If component is thick, compute its constant color to be                its average mean color.            -   If component is thin and has a regular polarity, then                compute its constant color to be average k darkest color                pixels.            -   If component is thin and has a reverse polarity, then                compute its constant color to be average k lightest                color pixels.    -   Visit all the thresholded components        -   If component is a text component, paint the component on the            foreground image using its computed constant color.        -   If component is a line-art component, paint the component on            the foreground image using its original color.

Reduce the foreground image by a factor R.

-   -   Mark all the pixels in the reduced image that have no painted        pixels in its corresponding block in the high resolution        foreground image as unpainted pixels.    -   Fill in the unpainted pixels in the reduced foreground image by        using the average color of the surrounding painted pixels.

Background Segmentation Method:

-   Find the dominant background region in the image    -   Find the smallest square S of length 2̂k, where k is an integer,        that contains the whole image.    -   Using Quad tree subdivision approach, recursively subdivide        Square S into four quadrants.        -   If size of the subdivided quadrant Sq is k2(=2)            -   Compute variance of the square Sq            -   If variance of the square is less than threshold T2                -   Allocate a new region R, with size and location of                    Sq.                -   Update region R with mean color and variance of Sq.                -   Add R to the region list L                -   Return from the recursive call and return the region                    list L        -   If all the pixels in a square fall outside the image, it            does not return a region list.        -   Merge all the regions in the (up to four) lists returned by            quadrants into a new list, and then examine that new list L.            If any two regions, R1 and R2, have similar means and their            combined variance is less than threshold T3, then we combine            R1 and R2 into a new region R3, and we update region R3's            mean, variance and size. We then remove R1 and R2 from list            L, and add R3 to the list, where it is treated the same as            any other region.        -   Return list L    -   Find the largest region in the List L at the top level and mark        it as background region B.    -   If B has less than a certain percentage P of pixels in the        image, where P is commonly 50%, the system and method stops the        background segmentation method and attempts the edge detection        method.    -   Compute mean color of the background B mean.    -   Create approximate MRC mask image by turning ON (turning to        black) all the pixels that are not part of the background B.    -   Form connected components on the approximate Mask image, and        label them as “approximate components”.        Classify the approximate components as text, line art, picture        or noise by examining the component features, including size,        area, height, width, stroke thickness, density, Euler number,        etc.-   Compute the final MRC mask image as follows-   Visit all the approximate components    -   If component is classified as a text component        -   Compute approximate foreground mean color Fmean as an            average of all the pixels in the original image that            correspond to the pixels of this component.        -   Compute the final component in the new mask as follows:            -   Visit all the pixels P in the original image that                correspond to this component.            -   If P is closer to Fmean than Bmean then we turn it ON in                the final Mask image, otherwise we turn it OFF.    -   If component is classified as a line art component        -   Divide the component's bounding box into k×k cells        -   If a given k×k cell has any ON pixels in the approximate            mask image that belong to this component            -   Threshold the cell and update the final mask image using                the thresholding procedure described for text                components.    -   If component is classified as a noise component        -   Do not paint it in the final mask image    -   If component is classified as a picture component        -   Do not paint it in the final mask image        -   Add it to the picture list Plist.-   If Background B has a variance below a certain threshold    -   Do no compute background image; replace it with the constant        color Bmean.-   Otherwise, compute the MRC background image    -   Compute dilation of the final mask image.    -   Remove all the pixels from the original image that are part of        the dilated mask.    -   Remove all the pixels from the original image that are part of        the picture regions stored in Plist.    -   Fill in the removed pixels with the average color of the        surrounding non-removed pixels.    -   Reduce foreground image by factor R (commonly 4 or 8).-   Compute the MRC foreground image

Foreground is computed using similar procedure as described in the EdgeSegmentation Method.

Example embodiments of the present invention are directed to a processorimplemented via any suitably appropriate hardware, programmed withsoftware to perform the various methods described above or portionsthereof.

Example embodiments of the present invention are directed to acomputer-readable hardware implemented medium having stored thereoninstructions adapted to be executed by a processor to perform thevarious methods described above or portions thereof.

Example embodiments of the present invention are directed to a method oftransmitting data including instructions executable by a processor toperform the various methods described above or portions thereof.

1. A method of segmenting a mask layer of an image, comprising: forming gradient components; using grayscale values of pixels adjacent to maximal gradient points within the gradient components to obtain respective threshold values for the gradient components; for each of the gradient components, using a respective one of said threshold values to threshold all pixels within a bounding box of the respective gradient component to form a respective thresholded component; and adding one or more of the thresholded components or an inverse of the one or more of the thresholded components to the mask layer.
 2. The method of claim 1, wherein the gradient components are formed by: selectively computing a set of maximal gradient points; selectively removing certain maximal gradient points; grouping remaining connected maximal gradient points into gradient components; and merging selected gradient components together.
 3. The method of claim 2, wherein the gradient components are removed if they are labeled as noise based on their area, height, width, stroke thickness, and Euler number.
 4. The method of claim 2, wherein the gradient components are divided into k by k cells, each of which is treated as a separate gradient component if the gradient components are labeled as line art based on their area, height, width, stroke thickness, and Euler number.
 5. The method of claim 2, wherein the maximal gradient points are only calculated if found in a k by k cell with a grayscale variance above a certain threshold.
 6. The method of claim 2, wherein the maximal gradient points are removed by smoothing and recomputing the maximal gradient points within a k by k cell when said cell contains a weighting of endpoints, singletons, k-junctions and gradient points which is above a certain threshold.
 7. The method of claim 2, wherein maximal gradient points which are closer to a first weakest peak than to a second weakest peak are removed, the first weakest peak being weaker than the second weakest peak.
 8. The method of claim 2, wherein the maximal gradient points remaining after the removal are formed into gradient components when they are connected.
 9. The method of claim 8, wherein overlapping gradient components are merged into a new gradient component.
 10. The method of claim 1, wherein, for each of the thresholded components, the thresholded component is added to the mask layer if it matches a corresponding one of the gradient components.
 11. The method of claim 10, wherein, if a thresholded component does not match any one of the gradient components, the method further comprising: inversing the thresholded component; and determining whether the inversed component matches a corresponding one of the gradient components; wherein, if a match is found for the inversed component, the inversed component is added to the mask layer.
 12. The method of claim 10, wherein matching criteria for the match is based on a bidirectional Rank Hausdorff between a perimeter of the thresholded component and the gradient component.
 13. The method of claim 1, wherein the threshold value is determined by creating a light array and a dark array and finding a value which maximizes a sum of a number of dark array pixels below said value plus a number of light array pixels equal to or above said value, where said arrays are formed by: traversing in a gradient direction of each of the maximal gradient points in the gradient component and identifying the lighter side and the darker side based on the value of the immediately adjacent neighbors of the corresponding pixel in grayscale space; and of grayscale values of two pixels on the lighter side, the two pixels including a first pixel immediately adjacent to the maximal gradient point and the second pixel following the first pixel in the gradient direction away from the maximal gradient point, placing the lighter of the two grayscale values into the light array; and of grayscale values of two pixels on the darker side, the two pixels including a first pixel immediately adjacent to the maximal gradient point and the second pixel following the first pixel in the gradient direction away from the maximal gradient point, placing the darker of the two grayscale values into the dark array.
 14. The method of claim 1, further comprising: for each of a plurality of k by k cells: dividing the cell into quadrants, dividing the cell into four vertical strips, and dividing the cell into four horizontal strips; and for the cell as a whole, for each quadrant, and for each strip, calculating a respective mean color value and a respective variance value; wherein the maximal gradient points are calculated for the cell conditional upon that the calculated values are not within a predetermined range of each other. 